﻿#include <iostream>
#include "Queue.h"
#include "Stack.h"
using std::cout;
using std::endl;
using std::cin;

void testQueue()
{
	cout << "Queue test begin" << endl;

	Queue queue;
	cout << "len: " << queue.getQueueLength() << endl;

	for (int i = 1; i <= 3; i++)queue.push(i);
	cout << "len: " << queue.getQueueLength() << endl;
	queue.print();

	cout << "front " << queue.front() << endl;
	for (int i = 1; i <= 3; i++)cout << "pop " << queue.pop() << endl;

	cout << "len: " << queue.getQueueLength() << endl;
	queue.print();

	cout << "Queue test end" << endl;
	cout << endl;
}

/*
b)	在栈中加入几个元素，用printStack()打印栈的内容，然后再从栈中取出这些元素，看是否正确
d)	测试判断栈是否为空的函数empty()的正确性
*/
void testStack()
{
	cout << "Stack test begin" << endl;

	Stack stack;
	cout << "empty? " << stack.empty() << endl;

	for (int i = 1; i <= 3; i++)stack.push(i);
	cout << "empty: " << stack.empty() << endl;
	stack.print();

	cout << "front " << stack.top() << endl;
	for (int i = 1; i <= 3; i++)cout << "pop " << stack.pop() << endl;

	cout << "empty: " << stack.empty() << endl;
	stack.print();

	cout << "Stack test end" << endl;
	cout << endl;
}

void test()
{
	Queue* q1 = new Queue;
	Stack* s1 = new Stack;
	LinkList* pl;
	for (int i = 1; i <= 3; i++)q1->push(i);
	for (int i = 1; i <= 5; i++)s1->push(i);
	//测试虚拟函数： 
	cout << "Test virtual member functions:" << endl;
	pl = q1;
	pl->print(); //应调用Queue::print() 
	pl = s1;  
	pl->print(); //应调用Stack::print() 
	pl->LinkList::print(); //应调用LinkList::print(); 

	delete q1;
	delete s1;
}
int main()
{
	testQueue();
	testStack();
	test();
	return 0;
}

/*（５）	编写测试用的主程序，主程序用于测试你所设计的三个类的正确性。测试内容包括：*/